package com.brainhealth.web.controller.customer;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.brainhealth.common.annotation.Anonymous;
import com.brainhealth.common.utils.SnowFlakeUtil;
import com.sun.jna.platform.win32.WinDef;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.brainhealth.common.annotation.Log;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.common.enums.BusinessType;
import com.brainhealth.customer.domain.ScoreMallGoodsCategory;
import com.brainhealth.customer.service.IScoreMallGoodsCategoryService;
import com.brainhealth.common.utils.poi.ExcelUtil;
import com.brainhealth.common.core.page.TableDataInfo;

/**
 * 积分商城商品分类Controller
 * 
 * @author wolong
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/customer/mallGoodsCategory")
public class ScoreMallGoodsCategoryController extends BaseController
{
    @Autowired
    private IScoreMallGoodsCategoryService scoreMallGoodsCategoryService;

    /**
     * 查询积分商城商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoodsCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreMallGoodsCategory scoreMallGoodsCategory)
    {
        startPage();
        List<ScoreMallGoodsCategory> list = scoreMallGoodsCategoryService.selectScoreMallGoodsCategoryList(scoreMallGoodsCategory);
        return getDataTable(list);
    }

    /**
     * 导出积分商城商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoodsCategory:export')")
    @Log(title = "积分商城商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreMallGoodsCategory scoreMallGoodsCategory)
    {
        List<ScoreMallGoodsCategory> list = scoreMallGoodsCategoryService.selectScoreMallGoodsCategoryList(scoreMallGoodsCategory);
        ExcelUtil<ScoreMallGoodsCategory> util = new ExcelUtil<ScoreMallGoodsCategory>(ScoreMallGoodsCategory.class);
        util.exportExcel(response, list, "积分商城商品分类数据");
    }

    /**
     * 获取积分商城商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoodsCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scoreMallGoodsCategoryService.selectScoreMallGoodsCategoryById(id));
    }

    /**
     * 新增积分商城商品分类
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoodsCategory:add')")
    @Log(title = "积分商城商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreMallGoodsCategory scoreMallGoodsCategory)
    {
        return toAjax(scoreMallGoodsCategoryService.insertScoreMallGoodsCategory(scoreMallGoodsCategory));
    }

    /**
     * 修改积分商城商品分类
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoodsCategory:edit')")
    @Log(title = "积分商城商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreMallGoodsCategory scoreMallGoodsCategory)
    {
        return toAjax(scoreMallGoodsCategoryService.updateScoreMallGoodsCategory(scoreMallGoodsCategory));
    }

    /**
     * 删除积分商城商品分类
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoodsCategory:remove')")
    @Log(title = "积分商城商品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scoreMallGoodsCategoryService.deleteScoreMallGoodsCategoryByIds(ids));
    }

    /**
     * 获取商品分类树形结构
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('customer:mallGoodsCategory:list')")
    @GetMapping("/mallGoodsCategoryTree")
    public AjaxResult mallGoodsCategoryTree()
    {
        return success(scoreMallGoodsCategoryService.getScoreMallGoodsCategoryTree());
    }

    /**
     * 根据商品分类ID获取商品所有父级分类
     * @param map
     * @return
     */
    @Anonymous
    @PostMapping("/getGoodsCategoryParentTree")
    public AjaxResult getGoodsCategoryParentTree(@RequestBody Map<String, Object> map)
    {
        Long categoryId = Long.parseLong(map.get("categoryId").toString());
        return success(scoreMallGoodsCategoryService.getScoreMallGoodsCategoryParentList(categoryId));
    }

    /**
     * 商城商品分类树
     * @return
     */
    @Anonymous
    @PostMapping("/goodsCategoryTree")
    public AjaxResult goodsCategoryTree(HttpServletRequest request)
    {
        return success(scoreMallGoodsCategoryService.getScoreMallGoodsCategoryTreeList(request));
    }

}
